<?php

namespace app\admin\service;

use app\admin\dao\MemberDao;
use app\admin\model\UM as UM;
use app\common\model\Member;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class PromoterService
 * @package app\member\service
 */
class PromoterService
{

    private MemberDao $memberDao;

    public function __construct(MemberDao $memberDao)
    {
        $this->memberDao = $memberDao;
    }

    /**
     * @param \app\admin\model\UM|null $user
     * @param $provinceId
     * @param $cityId
     * @param $startTime
     * @param $endTime
     * @param $kw
     * @param int|null $page
     * @param int|null $page_size
     * @return array
     */
    public function index(?UM $user, $provinceId, $cityId, $startTime, $endTime, $kw, ?int $page = null, ?int $page_size = null): array
    {
        if(is_numeric($endTime)){
            $endTime = TimeUtil::stamp(TimeUtil::DAY, $endTime, false);
        }
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->memberDao->listPromoters($provinceId, $cityId, $startTime, $endTime, $kw, $page, $page_size);
    }

    /**
     * 查询
     * @param UM|null $user
     * @param int $id
     * @return \app\common\model\Member
     */
    public function read(?UM $user, int $id): ?Member
    {
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->memberDao->findByPK($id, true);
    }

}
